<?php
// 本类由系统自动生成，仅供测试用途
class GroupAction extends Action {
	public $hTitle = "活动专题--";
	public $type = 'group';
	
	//主页面
    public function index(){
    	$this->assign('hTitle', $this->hTitle);
    	
    	$Group = M('group');
    	
    	//分页功能
		import("ORG.Util.Page");// 导入分页类
		$count      = $Group->count();// 查询满足要求的总记录数
		$Page       = new Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
		//获取数据
		$data = $Group->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		

		$this->assign('data',$data);
    	
    	$this->display();
    }
    
    //AJAX调用瀑布流
    public function ajax(){
    	$Group = M('group');
    	$p = $this->_get('p');
    	
	    //分页功能
		import("ORG.Util.Page");// 导入分页类
		$count      = $Group->count();// 查询满足要求的总记录数
		$Page       = new Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
		//获取数据
		$data = $Group->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		
		$this->assign('data',$data);
		
		if($Page->totalPages >= $p){
			$this->display();
		}
    }
    
    public function ajaxGoods(){
	    $id = $this->_get('id');
	    $p = $this->_get('p');
    	
    	//获取商品信息
    	$Group_Goods = M("group_goods");
    	//分页功能
		import("ORG.Util.Page");// 导入分页类
		$count      = $Group_Goods->where('group_id='.$id)->count();// 查询满足要求的总记录数
		$Page       = new Page($count,12);// 实例化分页类 传入总记录数和每页显示的记录数
		
		//获取数据
		$model=new Model();
    	$sql="SELECT G.type,G.id,G.title,G.img,G.collection,G.price from api_group_goods A LEFT JOIN api_goods G ON A.g_id=G.id where A.group_id= {$id} ORDER BY G.id LIMIT ".$Page->firstRow.','.$Page->listRows;    // =号后面写入你想要查询的A表的sid
    	$data = $model->query($sql);
    	
    	$this->assign('data', $data);
    	
    	//设置TITLE
    	$this->assign('hTitle', $GroupInfo['group_name'].'--'.$this->hTitle);
    	
	    if($Page->totalPages >= $p){
			$this->display();
		}
    }
    
    //详细信息页面
    public function info(){
    	$id = $this->_get('id');
    	
    	//获取商品信息
    	$Group = M('group');
    	$GroupInfo = $Group->where("`id`='".$id."'")->find();
    	
    	$this->assign('groupinfo',$GroupInfo);
    	
    	
    	$Group_Goods = M("group_goods");
    	//分页功能
		import("ORG.Util.Page");// 导入分页类
		$count      = $Group_Goods->where('group_id='.$id)->count();// 查询满足要求的总记录数
		$Page       = new Page($count,12);// 实例化分页类 传入总记录数和每页显示的记录数
		
		//获取数据
		$model=new Model();
    	$sql="SELECT G.type,G.id,G.title,G.img,G.collection,G.price from api_group_goods A LEFT JOIN api_goods G ON A.g_id=G.id where A.group_id= {$id} ORDER BY G.id LIMIT ".$Page->firstRow.','.$Page->listRows;    // =号后面写入你想要查询的A表的sid
    	$data = $model->query($sql);
    	
    	$this->assign('data', $data);
    	
    	//设置TITLE
    	$this->assign('hTitle', $GroupInfo['group_name'].'--'.$this->hTitle);
    	
	    $this->display();
    }
}